package jrain.fw.script.operator;

import jrain.fw.script.operator.BinaryOperator;
import jrain.fw.script.tools.ELException;
import jrain.fw.script.tools.Logger;

public class OrOperator extends BinaryOperator {

	public static final OrOperator SINGLETON = new OrOperator();

	public OrOperator() {
	}

	public String getOperatorSymbol() {
		return "or";
	}

	public Object apply(Object pLeft, Object pRight, Object pContext, Logger pLogger) throws ELException {
		// Coerce the values to booleans
		boolean left = Coercions.coerceToBoolean(pLeft, pLogger).booleanValue();
		boolean right = Coercions.coerceToBoolean(pRight, pLogger).booleanValue();

		return PrimitiveObjects.getBoolean(left || right);
	}

	public boolean shouldEvaluate(Object pLeft) {
		return (pLeft instanceof Boolean) && ((Boolean) pLeft).booleanValue() == false;
	}

	public boolean shouldCoerceToBoolean() {
		return true;
	}

}
